#ifndef __TOYM__NET__INET_ADDRESS_H__
#define __TOYM__NET__INET_ADDRESS_H__

#include <arpa/inet.h>
#include <string>

namespace toym
{
namespace net
{

class InetAddress {
public:

    InetAddress(short port);
    InetAddress(const char* ip, short port);
    InetAddress(const std::string& ip, short port);

    const struct sockaddr_in* getAddr() const {
        return &m_addr;
    }

    struct sockaddr_in* getAddr() { 
        return &m_addr; 
    }

    const struct sockaddr* getAddrConverted() const {
        return reinterpret_cast<const struct sockaddr*>(&m_addr); 
    }

    struct sockaddr* getAddrConverted() {
        return reinterpret_cast<struct sockaddr*>(&m_addr); 
    }

    short getPort();

    const char* toIpPort() const ;

    std::string toString() const ;

    void update(struct sockaddr_in* addr);

private:
    struct sockaddr_in m_addr;
    mutable char* m_pIpPortStr;
    mutable char m_ipPortStr[32];
};

} // namespace net

} // namespace toym


#endif //__TOYM__NET__INET_ADDRESS_H__